<%@ include file="/WEB-INF/common/taglibs.jsp"%>
<%@ page import="java.util.List"%>
<%@ page import="com.oss.model.Tag"%>
<%@ page import="com.oss.service.system.CacheService"%>
<%
	// 生成Option选项
	StringBuilder sb = new StringBuilder();
	List<Tag> tags = CacheService.getChildTags();
	sb.append("<select>");
	sb.append("<option value='notSet'>notSet</option>");
	for (Tag tag : tags) {
		sb.append("<option value='").append(tag.getId()).append("'>")
				.append(tag.getName()).append("</option>");
	}
	sb.append("</select>");
	String selectHtml = sb.toString();
%>
<script type="text/javascript"> 
var prj='';
$(document).ready(function(){	
	$("#table_prjs").tableSorter({
		sortClassAsc: 'headerSortUp',
		sortClassDesc: 'headerSortDown',
		headerClass: 'header'
	}).tableEditor({
		EDIT_HTML: 'Edit',
		SAVE_HTML: 'Save',
		FUNC_PRE_EDIT: 'preEdit',
		FUNC_PRE_SAVE: 'preSave',
		FUNC_UPDATE: 'updateTable'
	});
});
function preEdit(o){
	var col = o.row[5];
	var val = col.innerHTML;
	var html = "<%=selectHtml%>";
	$(col).html(html).find('select option').each(function(){
		if ($(this).val() == val){
			$(this).attr("selected", true);
		}
	});
}
function preSave(o){
	prj='';
	o.row.find("input,select").each(function(){
		prj += $(this).val()+"-,-";
	}).end();
}
function updateTable(o){
	$.ajax({
		url: '/ajax/admin/updateProject.do?prj=' + prj,
		type: 'POST',
		timeout: 10000,
		error: function(){alert('update failed!');},
		success: function(){}
	});
	var val = $(o.row[5]).find("select").val();
	$(o.row[5]).html(val);
}
</script>

<div class="pageMenu"><c:if test="${param.pageIndex gt 1}">
	<a
		href="<c:url value="/admin/batchEditPrjs.do?tagId=${param.tagId}&pageIndex=${param.pageIndex-1}&pageSize=${param.pageSize}"/>">Previous&nbsp;Page</a>
</c:if>&nbsp;&nbsp;<a
	href="<c:url value="/admin/batchEditPrjs.do?tagId=${param.tagId}&pageIndex=${param.pageIndex+1}&pageSize=${param.pageSize}"/>">Next&nbsp;Page</a></div>
<table align="center" id="table_prjs">
	<thead>
		<tr>
			<th>Id</th>
			<th>Name</th>
			<th>Source</th>
			<!-- <th>URL</th> -->
			<th>License</th>
			<th>Label</th>
			<th style="width: 200px;">Tag</th>
			<th>Enabled</th>
			<th>Action</th>
		</tr>
	</thead>
	<tbody>
		<c:forEach var="prj" items="${prjs}">
			<tr>
				<td>${prj.id}</td>
				<td>${prj.name}</td>
				<td>${prj.source}</td>
				<!-- <td>${prj.url}</td> -->
				<td>${prj.license}</td>
				<td>${prj.label}</td>
				<td>${prj.tag}</td>
				<td>${prj.enabled}</td>
				<td><a href="#" class="tsEditLink">Edit</a></td>
			</tr>
		</c:forEach>
	</tbody>
</table>
<div class="pageMenu"><c:if test="${param.pageIndex gt 1}">
	<a
		href="<c:url value="/admin/batchEditPrjs.do?tagId=${param.tagId}&pageIndex=${param.pageIndex-1}&pageSize=${param.pageSize}"/>">Previous&nbsp;Page</a>
</c:if>&nbsp;&nbsp;<a
	href="<c:url value="/admin/batchEditPrjs.do?tagId=${param.tagId}&pageIndex=${param.pageIndex+1}&pageSize=${param.pageSize}"/>">Next&nbsp;Page</a></div>